import { getCookie, delCookie } from './helper';

// Auth 身份验证
export function getAuthHeader(ssoToken) {
  return ({
    headers: {
      Accept: 'application/json',
      // Authorization  'Authorization': 'Bearer ' + ssoToken,
      Authorization: `Bearer ${ssoToken}`,
      'Content-Type': 'application/json; charset=utf-8',
    },
  });
}

// 重定向的登录
export function redirectLogin() {
  localStorage.clear();
  window.location.href = `http://222.27.227.25:80/student/login?redirect_url=${window.location.origin}`;
}

// 通过身份验证
export function authenticated() {
  const ssoToken = getCookie('sso_token');
  if (!ssoToken) {
    redirectLogin();
  }
}

// 注销
export function logOut() {
  delCookie({
    name: 'ssoToken',
    path: '/',
    domain: '.corp.visiondk.com',
  });
  authenticated();
}
